﻿namespace JxcLite;

public static class AppConfig
{
    public static string AppId => "JxcLite";
    public static string AppName => "进销存管理系统";

    public static void AddApplication(this IServiceCollection services, AppType type)
    {
#if DEBUG
        Config.IsDebug = true;
        Config.IsDevelopment = true;
#endif
        Console.WriteLine(AppName);
        Config.RenderMode = RenderType.Auto;

        var assembly = typeof(AppConfig).Assembly;
        Config.AddModule(assembly);

        services.AddKnown(option =>
        {
            option.Id = AppId;
            option.Name = AppName;
            option.Type = type;
            option.Assembly = assembly;
            option.DefaultPageSize = 20;
        });
        services.AddModules();
        services.ConfigUI();
    }

    public static void AddApplicationClient(this IServiceCollection services, Action<ClientOption> action)
    {
        var assembly = typeof(AppConfig).Assembly;
        services.AddKnownClient(action);
        services.AddClients(assembly);
    }

    private static void ConfigUI(this IServiceCollection services)
    {
        UIConfig.EnableEdit = false;
        //UIConfig.Copyright = string.Empty;
        //UIConfig.SoftTerms = string.Empty;
        UIConfig.TagColor = GetTagColor;

        KStyleSheet.AddStyle("_content/JxcLite/css/web.css");
        KStyleSheet.AddStyle("css/app.css");
    }

    private static string GetTagColor(string text)
    {
        if (text == BillType.Import) return "blue";
        else if (text == BillType.ImportReturn) return "orange";
        else if (text == BillType.Export) return "success";
        else if (text == BillType.ExportReturn) return "purple";
        else if (text == "现金") return "gold";
        else if (text == "微信") return "green";
        else if (text == "支付宝") return "blue";
        else if (text == "对账") return "processing";
        return "";
    }
}